<style>
    #group-add {
        padding: 20px 30px 0 0;
    }

    #group-add .layui-textarea, #group-add .layui-input {
        border-radius: 4px !important;
    }
</style>
<div class="layui-fluid" id="group-add">
    <form class="layui-form" action="" lay-filter="group-add-form">
        <div class="layui-form-item">
            <label class="layui-form-label ebe-required">规格组名：</label>
            <div class="layui-input-block">
                <input type="text" name="groupName" minlength="2" maxlength="10"
                       lay-verify="required|range" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述：</label>
            <div class="layui-input-block">
                <input type="text" name="description" minlength="2" maxlength="100"
                          lay-verify="range" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label ebe-required">状态：</label>
            <div class="layui-input-block">
                <input type="checkbox" name="standard" value="true" lay-skin="switch" lay-text="标准|非标准" checked>
            </div>
        </div>

        <div class="layui-form-item layui-ebe-btn ebe-hide">
            <button class="layui-btn ebe-layer-btn" lay-submit="" lay-filter="group-add-form-submit" id="submit">提交</button>
            <button type="reset" class="layui-btn ebe-layer-btn layui-btn-primary" id="reset">重置</button>
        </div>
    </form>
</div>
<script data-th-inline="javascript">
    layui.use(['layuimini', 'form', 'validate', 'table'], function () {
        let $ = layui.jquery,
            table = layui.table,
            layuimini = layui.layuimini,
            form = layui.form,
            validate = layui.validate;

        form.verify(validate);
        form.render();

        form.on('submit(group-add-form-submit)', function (data) {
            layuimini.post('/spec/group', addParams(data.field), function () {
                layer.closeAll();
                layuimini.alert.success('新增规格组成功!');
                table.reload('groupTable', {
                    data: data.field,
                    page: {
                        curr: layuimini.judgeAddTablePage('groupTable')
                    }
                });
            });
            return false;
        });

        function addParams(data) {
            let params = {
                groupName: data.groupName.trim(),
                standard : data.standard
            };
            if (data.description !== "") {
                params.description = data.description.trim();
            }
            return params;
        }
    });
</script>
